package com.hxzy.servlet.tbexpresscompany;

import com.hxzy.entity.TbExpressCompany;
import com.hxzy.service.TbExpressCompanyService;
import com.hxzy.service.impl.TbExpressCompanyServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@WebServlet("/TbExpressCompany/insert")
public class insert extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/WEB-INF/TbExpressCompany/insert.jsp").forward(req,resp);
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        res.setCharacterEncoding("UTF-8");
        res.setContentType("text/html;charset=UTF-8");

        TbExpressCompany company=new TbExpressCompany();

        String expressCorpId=req.getParameter("expressCorpId");
        company.setExpressCorpId(expressCorpId);

        /**
         * 快递公司名称
         */
        String expressCorpName=req.getParameter("expressCorpName");
        company.setExpressCorpName(expressCorpName);

        /**
         * 0 可用 1 不可用
         */
        Byte status=Byte.parseByte(req.getParameter("status"));
        company.setStatus(status);

        /**
         * 快递公司logo
         */
        String logoUrl=req.getParameter("logoUrl");
        company.setLogoUrl(logoUrl);

        TbExpressCompanyService service=new TbExpressCompanyServiceImpl();
        boolean insert = service.insert(company);

//        PrintWriter out=res.getWriter();
//        out.println( insert? "新增成功": "新增失败");
//        //输出刷新
//        out.flush();
//        out.close();

        String path=req.getContextPath();
        req.setAttribute("url",path+"/TbExpressCompany/search");
        //转发
        req.getRequestDispatcher("/WEB-INF/jump.jsp").forward(req,res);

    }
}
